package com.example.ch03.materialdesign.button;

import android.os.Bundle;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;

import com.example.ch03.materialdesign.R;

public class CheckBoxDemoActivity extends AppCompatActivity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.checkbox_01);

        // No handling in here for the Chicken checkbox

        CheckBox fishCB = (CheckBox) findViewById(R.id.fishCB);

        if (fishCB.isChecked())
            fishCB.toggle(); // flips the checkbox to unchecked if it was
        // checked

        fishCB.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

            public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
                Toast.makeText(
                        CheckBoxDemoActivity.this,
                        "The fish checkbox is now "
                                + (isChecked ? "checked" : "not checked"),
                        Toast.LENGTH_SHORT).show();

            }
        });
    }

    public void doClick(View view) {
        Toast.makeText(
                this,
                "The steak checkbox is now "
                        + (((CheckBox) view).isChecked() ? "checked"
                        : "not checked"), Toast.LENGTH_SHORT).show();
    }
}
